﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Echart
{
    public partial class Form1 : Form
    {
        List<Car> carLists = new List<Car>();
        List<CompanyMoney> moenyLists = new List<CompanyMoney>();
        List<Color> colorLists = new List<Color>();

        List<PointXY> PointXYs = new List<PointXY>();
        /// <summary>
        /// 曲线条数
        /// </summary>
        int seriesCount = 2;
        public Form1()
        {
            InitializeComponent();
            InitCarData();
            InitColor();
            EchartHelper.InitEchart3D(chart1, carLists, colorLists, System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Column, "汽车");

            colorLists.Clear();
            InitCompanyData();
            Color color1 = System.Drawing.Color.FromArgb(((int)(((byte)(220)))), ((int)(((byte)(224)))), ((int)(((byte)(64)))), ((int)(((byte)(10)))));
            colorLists.Add(color1);
            EchartHelper.InitEchart(chart2, moenyLists, colorLists, System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline, "利润");


            EchartHelper.InitDynamicEchart(chart3,seriesCount);
            timer1.Interval = 280;

        }
        /// <summary>
        /// 初始化数据
        /// </summary>
        public void InitCarData()
        {
            carLists.Add(new Car("奥迪", 2, 4, 8));
            carLists.Add(new Car("奔驰", 4, 8, 16));
            carLists.Add(new Car("宝马", 8, 4, 8));
            carLists.Add(new Car("比亚迪", 4, 4, 8));
        }
        public void InitCompanyData()
        {
            moenyLists.Add(new CompanyMoney("一月", 23654));
            moenyLists.Add(new CompanyMoney("二月", 53654));
            moenyLists.Add(new CompanyMoney("三月", 43654));
            moenyLists.Add(new CompanyMoney("四月", 33654));
            moenyLists.Add(new CompanyMoney("五月", 27654));
            moenyLists.Add(new CompanyMoney("六月", 23654));
            moenyLists.Add(new CompanyMoney("七月", 45654));
            moenyLists.Add(new CompanyMoney("八月", 23654));
            moenyLists.Add(new CompanyMoney("九月", 33654));
            moenyLists.Add(new CompanyMoney("十月", 23654));
            moenyLists.Add(new CompanyMoney("十一月", 33654));
            moenyLists.Add(new CompanyMoney("十二月", 32654));
        }
        /// <summary>
        /// 初始化图表标题
        /// </summary>
        /// <param name="title"></param>
        public void InitChartTitle(string title)
        {
            System.Windows.Forms.DataVisualization.Charting.Title title1 = new System.Windows.Forms.DataVisualization.Charting.Title();
            title1.Alignment = System.Drawing.ContentAlignment.TopCenter;
            title1.Font = new System.Drawing.Font("Trebuchet MS", 14.25F, System.Drawing.FontStyle.Bold);
            title1.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(26)))), ((int)(((byte)(59)))), ((int)(((byte)(105)))));
            title1.Name = "Title1";
            title1.Position.Auto = false;
            title1.Position.Height = 8.738057F;
            title1.Position.Width = 80F;
            title1.Position.X = 10F;
            title1.Position.Y = 4F;
            title1.ShadowColor = System.Drawing.Color.FromArgb(((int)(((byte)(32)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))));
            title1.ShadowOffset = 3;
            title1.Text = title;
            chart1.Titles.Add(title1);
        }
        /// <summary>
        /// 初始化颜色
        /// </summary>
        public void InitColor()
        {
            Color color1 = System.Drawing.Color.FromArgb(((int)(((byte)(220)))), ((int)(((byte)(65)))), ((int)(((byte)(140)))), ((int)(((byte)(240)))));
            Color color2 = System.Drawing.Color.FromArgb(((int)(((byte)(220)))), ((int)(((byte)(252)))), ((int)(((byte)(180)))), ((int)(((byte)(65)))));
            Color color3 = System.Drawing.Color.FromArgb(((int)(((byte)(220)))), ((int)(((byte)(224)))), ((int)(((byte)(64)))), ((int)(((byte)(10)))));

            colorLists.Add(color1);
            colorLists.Add(color2);
            colorLists.Add(color3);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            timer1.Start();
        }

        Random rand = new Random();
        private void timer1_Tick(object sender, EventArgs e)
        {
            PointXYs.Clear();
            for (int i = 0; i < seriesCount; i++)
            {
                PointXYs.Add(new PointXY(0, rand.Next(20, 60)));
            }
            EchartHelper.timerTick(chart3, PointXYs);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            timer1.Stop();
        }
    }

}


